package com.springcloud.model.base.Res;

import com.springcloud.model.rest.RestEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author shengtao
 * @Description:
 * @date 2019/06/04 20:43
 */

@Data
@Builder
public class BaseRes<T> {

    private String code;

    private String msg;

    private T data;

    public BaseRes(){}

    public BaseRes(RestEnum restEnum,T data){
        this.code = restEnum.code();
        this.msg = restEnum.msg();
        this.data = data;
    }

    public BaseRes(String code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseRes<T> success(T data){
        return new BaseRes<T>(RestEnum.SUCCESS,data);
    }

    public static BaseRes error(RestEnum restEnum){
        return new BaseRes(restEnum,null);
    }



}
